var menuobj="";
//set this variable to 1 if you wish the URLs of the highlighted menu to be displayed in the status bar
var display_url=0;
var current_map_object = "";

function CreateMenu() {
	//Menu principale
	var div_ie5menu = document.createElement('DIV');
	div_ie5menu.id="ie5menu";
	div_ie5menu.className="skin0";
	div_ie5menu.onmouseover=function(e){highlightie5(e)};
	div_ie5menu.onmouseout=function(e){lowlightie5(e)};
	div_ie5menu.onclick=function(e){jumptoie5(e)};
	div_ie5menu.style.display="none";
	
	//Voci menu
	//Informazioni
	var menu_informazioni = document.createElement('DIV');
	menu_informazioni.className="menuitems";	
	menu_informazioni.setAttribute("url","javascript:EEToDo()");		
	menu_informazioni.innerHTML="<img src=images/KAJAXinfo.gif>&nbsp;Informazioni";
	
	//Elimina

	var menu_elimina = document.createElement('DIV');
	menu_elimina.className="menuitems";	
	menu_elimina.setAttribute("url","javascript:EliminaElemento(current_map_object.id)");		
	menu_elimina.innerHTML="<img src=images/KAJAXdelete.gif>&nbsp;Elimina";
	
	
	
	div_ie5menu.appendChild(menu_informazioni);
	div_ie5menu.appendChild(menu_elimina);
	document.body.appendChild(div_ie5menu);
	
	

	
	var ie5=document.all&&document.getElementById
	var ns6=document.getElementById&&!document.all
	menuobj=document.getElementById("ie5menu");
	menuobj.style.display='';
	document.oncontextmenu=showmenuie5;
	document.onclick=hidemenuie5;

	
}






function showmenuie5(e){
//Find out how close the mouse is to the corner of the window
//var rightedge=ie5? document.body.clientWidth-event.clientX : window.innerWidth-e.clientX
//var bottomedge=ie5? document.body.clientHeight-event.clientY : window.innerHeight-e.clientY

var rightedge=browser.isIE? document.body.clientWidth-event.clientX : window.innerWidth-e.clientX
var bottomedge=browser.isIE? document.body.clientHeight-event.clientY : window.innerHeight-e.clientY

//Aggiustamento posizione del menu
/*rightedge = rightedge - 100;
bottomedge = bottomedge - 100;*/




var oggetto = browser.isIE? event.srcElement : e.target;
current_map_object = oggetto;
try {
	if (oggetto.className != 'mapItem') return 0;
} catch(e) {}


//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<menuobj.offsetWidth)
//move the horizontal position of the menu to the left by it's width
menuobj.style.left=browser.isIE? document.body.scrollLeft+event.clientX-menuobj.offsetWidth + 10 : window.pageXOffset+e.clientX-menuobj.offsetWidth + 10
else
//position the horizontal position of the menu where the mouse was clicked
menuobj.style.left=browser.isIE? document.body.scrollLeft+event.clientX + 10 : window.pageXOffset+e.clientX + 10

//same concept with the vertical position
if (bottomedge<menuobj.offsetHeight)
menuobj.style.top=browser.isIE? document.body.scrollTop+event.clientY-menuobj.offsetHeight : window.pageYOffset+e.clientY-menuobj.offsetHeight
else
menuobj.style.top=browser.isIE? document.body.scrollTop+event.clientY : window.pageYOffset+e.clientY

menuobj.style.visibility="visible"
return false
}

function hidemenuie5(e){
menuobj.style.visibility="hidden"
}

function highlightie5(e){
var firingobj=browser.isIE? event.srcElement : e.target
if (firingobj.className=="menuitems"||browser.isNS&&firingobj.parentNode.className=="menuitems"){
if (browser.isNS&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode //up one node
firingobj.style.backgroundColor="highlight"
firingobj.style.color="white"
if (display_url==1)
window.status=event.srcElement.url
}
}

function lowlightie5(e){
var firingobj=browser.isIE? event.srcElement : e.target
if (firingobj.className=="menuitems"||browser.isNS&&firingobj.parentNode.className=="menuitems"){
if (browser.isNS&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode //up one node
firingobj.style.backgroundColor=""
firingobj.style.color="black"
window.status=''
}
}

function jumptoie5(e){
var firingobj=browser.isIE? event.srcElement : e.target
if (firingobj.className=="menuitems"||browser.isNS&&firingobj.parentNode.className=="menuitems"){
if (browser.isNS&&firingobj.parentNode.className=="menuitems") firingobj=firingobj.parentNode
if (firingobj.getAttribute("target"))
window.open(firingobj.getAttribute("url"),firingobj.getAttribute("target"))
else
window.location=firingobj.getAttribute("url")
}
}

/*if (ie5||ns6){
menuobj.style.display=''
document.oncontextmenu=showmenuie5
document.onclick=hidemenuie5
}*/